// pages/user/order/refund-express.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        refundId: 0,
        detail: null,
        expressList: [],
        expressIndex: -1,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.data.refundId = options.id;
        this.setData({
            refundId: options.id
        });

        wx.http.post('api/user.refund/detail', {
            order_refund_id: this.data.refundId
        }).then((res) => {
            const detail = res.data.data.detail;
            const expressList = res.data.data.expressList;

            this.setData({
                detail: detail,
                expressList: expressList,
            });
            return detail;
        }, (err) => {
            console.warn("api/user.refund/detail", err)
        });
    },

    // 快递列表
    bindExpressChange: function (e) {
        this.setData({
            expressIndex: e.detail.value
        });
    },

    // 提交数据
    onSubmit: function (e) {
        const values = e.detail.value;
        console.log(values);

        const expressList = this.data.expressList;
        const expressIndex = this.data.expressIndex;
        if (!expressList[expressIndex]) {
            wx.showToast({
                title: '请选择物理公司！',
                icon: 'none',
            });
            return;
        }
        const express = expressList[expressIndex];

        wx.http.post('api/user.refund/delivery', {
            order_refund_id: this.data.refundId,
            express_id: express.express_id,
            express_no: values.express_no
        }).then((res) => {
            wx.showModal({
                content: '填写完成！',
                showCancel: false,
                success: function (res) {
                    wx.navigateBack({})
                },
            })
        }, (err) => {
            console.warn("api/user.refund/delivery", err)
        });
    }

})